package acme.serviceproviders.data.utility;

import java.util.*;

public class DateHelper {
	private static final int MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24;
	
	public static long countDaysBetween(Date start, Date end)
	{
		if (end.before(start)) {
			throw new IllegalArgumentException("The end date must be later than the start date");
		}
		
		Calendar startCal = GregorianCalendar.getInstance();
        startCal.setTime(start);
        startCal.set(Calendar.HOUR_OF_DAY, 0);
        startCal.set(Calendar.MINUTE, 0);
        startCal.set(Calendar.SECOND, 0);
        long startTime = startCal.getTimeInMillis();

        Calendar endCal = GregorianCalendar.getInstance();
		endCal.setTime(end);
		endCal.set(Calendar.HOUR_OF_DAY, 0);
		endCal.set(Calendar.MINUTE, 0);
		endCal.set(Calendar.SECOND, 0);
		long endTime = endCal.getTimeInMillis();
		
		return (endTime - startTime) / MILLISECONDS_IN_DAY;
	}
}
